﻿using Com.Ctrip.Framework.Apollo;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ManaSky.Apollo
{
    public class AppsettingsHelper
    {
        private static IConfiguration _config;

        private static IConfiguration Config
        {
            get
            {
                if (_config == null)
                {
                    _config = new ConfigurationBuilder()
                        .SetBasePath(Path.Combine(Directory.GetCurrentDirectory()))
                        .AddJsonFile("appsettings.json", false).Build();
                }
                return _config;
            }
        }
        public static void SetConfiguration(IConfiguration Configs)
        {
            _config = Configs;
        }

        public static string GetConfig(string key)
        {
            var value = GetConfig<string>(key);
            return value;
        }
        public static T GetConfig<T>(string key)
        {
            //T value1 = Config.GetValue<T>(key);
            T value = Config.GetSection(key).Get<T>();
            return value;
        }
    }
}
